import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _class2;

/**
 * Drawer - 消息模板明细模板参数
 * @date: 2019-10-9
 */
import React from 'react';
import { Form, Input, Modal, Button, Popconfirm } from 'antd';
import { Bind } from 'lodash-decorators';
import EditTable from 'components/EditTable';
import TLEditor from 'components/TLEditor';
import { Button as ButtonPermission } from 'components/Permission';
import intl from 'utils/intl';
import { getEditTableData } from 'utils/utils';
var Drawer = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec8 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(Drawer, _React$PureComponent);

  var _super = _createSuper(Drawer);

  function Drawer() {
    _classCallCheck(this, Drawer);

    return _super.apply(this, arguments);
  }

  _createClass(Drawer, [{
    key: "handleSearch",
    value: function handleSearch() {
      var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var _this$props$onSearch = this.props.onSearch,
          onSearch = _this$props$onSearch === void 0 ? function (e) {
        return e;
      } : _this$props$onSearch;
      onSearch(params);
    }
  }, {
    key: "handleReset",
    value: function handleReset() {
      var form = this.props.form;
      form.resetFields();
    }
  }, {
    key: "handleInit",
    value: function handleInit() {
      var _this$props$onInit = this.props.onInit,
          onInit = _this$props$onInit === void 0 ? function (e) {
        return e;
      } : _this$props$onInit;
      onInit();
    }
  }, {
    key: "handleDelete",
    value: function handleDelete(record) {
      var _this$props$onDelete = this.props.onDelete,
          onDelete = _this$props$onDelete === void 0 ? function (e) {
        return e;
      } : _this$props$onDelete;
      onDelete(record);
    }
  }, {
    key: "handleCreate",
    value: function handleCreate() {
      var _this$props$onCreate = this.props.onCreate,
          onCreate = _this$props$onCreate === void 0 ? function (e) {
        return e;
      } : _this$props$onCreate;
      onCreate({
        _status: 'create'
      });
    }
  }, {
    key: "handleSave",
    value: function handleSave(record) {
      var _this$props = this.props,
          _this$props$onOk = _this$props.onOk,
          onOk = _this$props$onOk === void 0 ? function (e) {
        return e;
      } : _this$props$onOk,
          dataSource = _this$props.dataSource;
      var params = getEditTableData(dataSource).filter(function (item) {
        return item.argId === record.argId;
      });
      onOk(params[0]);
    }
  }, {
    key: "handlePagination",
    value: function handlePagination(pagination) {
      this.handleSearch({
        page: pagination
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props2 = this.props,
          _this$props2$onCancel = _this$props2.onCancel,
          onCancel = _this$props2$onCancel === void 0 ? function (e) {
        return e;
      } : _this$props2$onCancel,
          _this$props2$onEdit = _this$props2.onEdit,
          onEdit = _this$props2$onEdit === void 0 ? function (e) {
        return e;
      } : _this$props2$onEdit,
          _this$props2$fetchLoa = _this$props2.fetchLoading,
          fetchLoading = _this$props2$fetchLoa === void 0 ? false : _this$props2$fetchLoa,
          _this$props2$loading = _this$props2.loading,
          loading = _this$props2$loading === void 0 ? false : _this$props2$loading,
          _this$props2$visible = _this$props2.visible,
          visible = _this$props2$visible === void 0 ? false : _this$props2$visible,
          _this$props2$dataSour = _this$props2.dataSource,
          dataSource = _this$props2$dataSour === void 0 ? [] : _this$props2$dataSour,
          _this$props2$paginati = _this$props2.pagination,
          pagination = _this$props2$paginati === void 0 ? {} : _this$props2$paginati,
          path = _this$props2.path,
          form = _this$props2.form;
      var columns = [{
        title: intl.get('cmsg.messageTemplate.model.template.argName').d('参数名称'),
        dataIndex: 'argName',
        width: 150
      }, {
        title: intl.get('cmsg.messageTemplate.model.template.description').d('参数描述'),
        dataIndex: 'description',
        render: function render(val, record) {
          if (record._status === 'update') {
            var getFieldDecorator = record.$form.getFieldDecorator;
            return /*#__PURE__*/React.createElement(Form.Item, null, getFieldDecorator('description', {
              initialValue: val
            })( /*#__PURE__*/React.createElement(TLEditor, {
              label: intl.get('cmsg.messageTemplate.model.template.description').d('参数描述'),
              field: "description" // eslint-disable-next-line
              ,
              token: record._token
            })));
          } else {
            return val;
          }
        }
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        width: 120,
        render: function render(_, record) {
          if (record._status === 'update') {
            return /*#__PURE__*/React.createElement("span", {
              className: "action-link"
            }, /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.cancelEdit"),
                type: 'button',
                meaning: '模板参数-取消编辑'
              }],
              onClick: function onClick() {
                return onEdit(record, false);
              }
            }, intl.get('cpaas.common.button.cancel').d('取消')), /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.save"),
                type: 'button',
                meaning: '模板参数-保存'
              }],
              onClick: function onClick() {
                return _this.handleSave(record);
              }
            }, intl.get('cpaas.common.button.save').d('保存')));
          } else if (record._status !== 'update') {
            return /*#__PURE__*/React.createElement("span", {
              className: "action-link"
            }, /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.edit"),
                type: 'button',
                meaning: '模板参数-编辑'
              }],
              onClick: function onClick() {
                return onEdit(record, true);
              }
            }, intl.get('cpaas.common.button.edit').d('编辑')), /*#__PURE__*/React.createElement(Popconfirm, {
              title: intl.get('cpaas.common.message.confirm.delete').d('是否删除此条记录？'),
              onConfirm: function onConfirm() {
                return _this.handleDelete(record);
              }
            }, /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.delete"),
                type: 'button',
                meaning: '模板参数-删除'
              }]
            }, intl.get('cpaas.common.button.delete').d('删除'))));
          }
        }
      }];
      return /*#__PURE__*/React.createElement(Modal, {
        width: "620px",
        destroyOnClose: true,
        transitionName: "move-right",
        wrapClassName: "ant-modal-sidebar-right",
        title: intl.get('cmsg.messageTemplate.view.message.title.detail.para').d('模板参数'),
        visible: visible,
        onCancel: onCancel,
        footer: null
      }, /*#__PURE__*/React.createElement(Form, {
        layout: "inline"
      }, /*#__PURE__*/React.createElement(Form.Item, {
        label: intl.get('cmsg.messageTemplate.model.template.argName').d('参数名称')
      }, form.getFieldDecorator('argName')( /*#__PURE__*/React.createElement(Input, null))), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
        onClick: this.handleReset,
        style: {
          marginRight: '8px'
        }
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: function onClick() {
          return _this.handleSearch();
        }
      }, intl.get('cpaas.common.button.search').d('查询')))), /*#__PURE__*/React.createElement("div", {
        style: {
          display: 'flex',
          justifyContent: 'flex-end'
        },
        className: "table-list-operator"
      }, /*#__PURE__*/React.createElement(ButtonPermission, {
        permissionList: [{
          code: "".concat(path, ".button.init"),
          type: 'button',
          meaning: '模板参数-初始化'
        }],
        type: "primary",
        disabled: loading,
        onClick: this.handleInit
      }, intl.get('cmsg.messageTemplate.model.template.init').d('初始化'))), /*#__PURE__*/React.createElement(EditTable, {
        bordered: true,
        rowKey: "argId",
        columns: columns,
        loading: fetchLoading || loading,
        dataSource: dataSource,
        pagination: pagination,
        onChange: this.handlePagination
      }));
    }
  }]);

  return Drawer;
}(React.PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "handleSearch", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSearch"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleReset", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleReset"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleInit", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleInit"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleDelete", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "handleDelete"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleCreate", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "handleCreate"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleSave", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSave"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handlePagination", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "handlePagination"), _class2.prototype)), _class2)) || _class);
export { Drawer as default };